package com.mrdeer.iot.bean;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.mrdeer.iot.bean.command.Protocol;
import com.mrdeer.iot.bean.enums.EMQExchange;
import io.netty.channel.Channel;
import io.netty.channel.ChannelId;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Arrays;

/**
 * @Author: xie jianchu
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class ChannelInfo implements Serializable {

    private static final long serialVersionUID = -5277501784220353492L;

    @JsonIgnore
    private ChannelId channelId;

    private String sn;

    private Protocol protocol;

    @JsonIgnore
    private Channel channel;

    private String command;

    /**
     * 消息队列标示
     */
    @JsonIgnore
    private EMQExchange[] emqExchanges;

    public static ChannelInfo build(String sn, ChannelId channelId, Channel channel) {
        return new ChannelInfo(sn, channelId, null, channel);
    }

    public static ChannelInfo build(String sn, ChannelId channelId, Protocol protocol, Channel channel) {
        return new ChannelInfo(sn, channelId, protocol, channel);
    }

    private ChannelInfo(String sn, ChannelId channelId, Protocol protocol, Channel channel) {
        this.channelId = channelId;
        this.sn = sn;
        this.protocol = protocol;
        this.channel = channel;
    }

    @Override
    public String toString() {
        return "ChannelInfo{" +
                "channelId=" + channelId +
                ", sn='" + sn + '\'' +
                ", protocol=" + protocol +
                ", channel=" + channel +
                ", emqExchanges=" + Arrays.toString(emqExchanges) +
                '}';
    }
}
